import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

public class Test {
    public static String mostCommonWord(String paragraph, String[] banned) {
        String s = paragraph.toLowerCase();
        char[] ss = s.toCharArray();
        HashMap<String,Integer> hash  = new HashMap();
        int start = 0;
        int end =0;
        for(int i = 0;i<ss.length;i++){
            if(ss[i] != ' ' && ss[i] != ',' && ss[i] != '!' && ss[i] != '?' && ss[i] != '\'' && ss[i] != '.' ){
                end++;
            }else{
                String str = s.substring(start,end);
                hash.put(str,hash.getOrDefault(str,0)+1);
                start = i+1;
                end++;
            }


        }
        String str = s.substring(start,end);
        hash.put(str,hash.getOrDefault(str,0)+1);


        System.out.println();
        for(int i =0;i<banned.length;i++){
            hash.remove(banned[i]);
        }
        hash.remove(" ");



        String keyWithMaxValue = getKeyWithMaxValue(hash);


        return keyWithMaxValue;


    }
    public static String getKeyWithMaxValue(HashMap<String, Integer> map) {
        String maxKey = null;
        int maxValue = Integer.MIN_VALUE;

        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            if (entry.getValue() > maxValue) {
                maxValue = entry.getValue();
                maxKey = entry.getKey();
            }
        }

        return maxKey;
    }

    public static void main(String[] args) {
    mostCommonWord("Bob hit a ball",new String[]{"hit"});

    }

}
